<?php

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Argument;
use app\common\model\User;

class TestUserPassword extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('user:testuserpassword')
            ->setDescription('测试用户密码');
        // 设置参数
        $this->addArgument('username', Argument::REQUIRED, '用户名')
            ->addArgument('password', Argument::REQUIRED, '密码');
    }

    protected function execute(Input $input, Output $output)
    {
    	// 指令输出
        $username = $input->getArgument('username');
        $password = $input->getArgument('password');

        /** @var User $user */
        $user = User::where('username', $username)->find();
        if (!$user) {
            $output->error('用户不存在');
            return;
        }

        if ($user->checkPasswordValid($password)) {
            $output->error('密码正确');
        } else {
            $output->error('密码错误');
        }
    }
}
